package com.pureut.production.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.production.domain.dto.WeighingFinishedMaterialProductDto;
import com.pureut.production.domain.vo.PackageLabelVo;
import com.pureut.production.domain.vo.WarehousingVo;
import com.pureut.production.domain.vo.WeighingFinishedMaterialProductVo;
import com.pureut.production.service.WeighingFinishedMaterialProductService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/***
 * 成品称重控制层
 * Author:C
 * Date:2023/02/24 13:59
 * @DESC
 */
@RestController
@RequestMapping("/weighing-finished-material-product")
public class WeighingFinishedMaterialProductController extends BaseController {

    @Resource
    WeighingFinishedMaterialProductService weighingFinishedMaterialProductService;

    /**
     * 成品称重列表
     */
    @RequiresPermissions("productionTube:produAdm:slitting:produweight:list")
    @GetMapping("/list")
    public TableDataInfo getList(WeighingFinishedMaterialProductVo weighingFinishedMaterialProductVo) {
        startPage();
        //查询成品称重列表
        List<WeighingFinishedMaterialProductDto> list = weighingFinishedMaterialProductService.getList(weighingFinishedMaterialProductVo);
        return getDataTable(list);
    }

    /**
     * 单据明细下方列表
     */
    @GetMapping("/getViewList")
    public TableDataInfo getViewList(String splittingOrderNumber) {
        startPage();
        //查询单据明细下方列表
        List<WeighingFinishedMaterialProductDto> list = weighingFinishedMaterialProductService.getViewList(splittingOrderNumber);
        return getDataTable(list);
    }

    /**
     * 查看(成品称重)
     */
    @RequiresPermissions("productionTube:produAdm:slitting:produweight:team:weigh")
    @GetMapping("/getViewById/{id}")
    public AjaxResult getViewById(@PathVariable("id") Long id) {
        return AjaxResult.success(weighingFinishedMaterialProductService.getViewById(id));
    }

    /**
     * 信息打印，标签打印之后修改数据
     */
    @PutMapping("/updateData")
    @Log(title = "信息打印，标签打印之后修改数据", businessType = BusinessType.UPDATE)
    public AjaxResult updateData(@RequestBody WeighingFinishedMaterialProductVo weighingFinishedMaterialProductVo) {
        return toAjax(weighingFinishedMaterialProductService.updateData(weighingFinishedMaterialProductVo));
    }

    /**
     * 查看(条码修正)
     */
    @RequiresPermissions("productionTube:produAdm:slitting:produweight:team:correct")
    @GetMapping("/getBarCodeCorrection/{id}")
    public AjaxResult getBarCodeCorrection(@PathVariable("id") Long id) {
        return AjaxResult.success(weighingFinishedMaterialProductService.getBarCodeCorrection(id));
    }

    /**
     * 条码补打
     */
    @RequiresPermissions("productionTube:produAdm:slitting:produweight:team:patchwork")
    @GetMapping("/getReprint/{id}")
    public AjaxResult getReprint(@PathVariable("id") Long id) {
        return AjaxResult.success(weighingFinishedMaterialProductService.getReprint(id));
    }


    /**
     * 产出统计
     */
    @RequiresPermissions("productionTube:produAdm:slitting:produweight:team:produce")
    @GetMapping("/outputStatistics")
    public TableDataInfo outputStatistics(String splittingOrderNumber) {
        startPage();
        //查询产出统计列表
        List<WeighingFinishedMaterialProductDto> list = weighingFinishedMaterialProductService.outputStatistics(splittingOrderNumber);
        return getDataTable(list);
    }


    /**
     * 入库（pda）
     */
    @RequiresPermissions("productionTube:produAdm:slitting:produweight:team:warehou")
    @PostMapping("/warehousing")
    @Log(title = "入库（pda）", businessType = BusinessType.UPDATE)
    public AjaxResult warehousing(@RequestBody WarehousingVo warehouseVo) {
        return AjaxResult.success(weighingFinishedMaterialProductService.warehousing(warehouseVo));
    }

    /**
     * 新增
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody PackageLabelVo packageLabelVo) throws Exception {
        return toAjax(weighingFinishedMaterialProductService.add(packageLabelVo));
    }

    /**
     * 根据产品号码获取详情(feign调用)
     */
    @GetMapping("/getWeighingFinishedData")
    public AjaxResult getWeighingFinishedData(String materialNumber) {
        return AjaxResult.success(weighingFinishedMaterialProductService.getWeighingFinishedData(materialNumber));
    }

    /**
     * 根据产品号码获取详情(完工入库 feign调用)
     */
    @GetMapping("/getFinishedData")
    public AjaxResult getFinishedData(String materialNumber) {
        return AjaxResult.success(weighingFinishedMaterialProductService.getFinishedData(materialNumber));
    }

    /**
     * 根据母卷号码查询成品称重详情（产品追溯feign）
     */
    @GetMapping("/selectWeighingFinishedMaterialProductList")
    public AjaxResult selectWeighingFinishedMaterialProductList(String masterVolumeNumber) {
        return AjaxResult.success(weighingFinishedMaterialProductService.selectWeighingFinishedMaterialProductList(masterVolumeNumber));
    }

    /**
     * 通过小卷号码查询成品称重信息（产品追溯小卷基础信息feign）
     */
    @GetMapping("/selectBySmallVolumeNumber")
    public AjaxResult selectBySmallVolumeNumber(String smallVolumeNumber) {
        return AjaxResult.success(weighingFinishedMaterialProductService.selectBySmallVolumeNumber(smallVolumeNumber));
    }
}
